@Api(value = "模块名", description = "background/模块名")
@RestController
@RequestMapping(value = "/background/dmap-knowledge-server/v1/article")
public class MenuBackController {
    @Resource
    private MenuService menuService;
    @ResponseBody
    @ApiOperation(value = "新增模块名", notes = "新增模块名")
    @RequestMapping(value = "/insert", method = RequestMethod.POST)
    public BaseVo insertMenu(@RequestBody MenuParam param) {
        BaseVo result = new BaseVo();
        if ( param.getModuleId() == 0 || StringUtils.isBlank(param.getMenuCode())|| StringUtils.isBlank(param.getMenuName())|| StringUtils.isBlank(param.getDescription())|| StringUtils.isBlank(param.getWebUrl())|| StringUtils.isBlank(param.getIconUrl())|| StringUtils.isBlank(param.getCreateTime())|| param.getUpdateTime() == 0    ){            result.setCode(Constant.RESPONSE_PARAM_ERROR_CODE);
            result.setMsg(Constant.RESPONSE_PARAM_ERROR_MSG);
            return result;
        }
        //进行字符串的数字验证
        int success = menuService.insertMenu(param);
       if (success == 0) {
           result.setCode(Constant.RESPONSE_INSERT_ERROR_CODE);
           result.setMsg(Constant.RESPONSE_INSERT_ERROR_MSG);
        }
        return result;
    }
    @ResponseBody
   @ApiOperation(value = "修改模块名", notes = "修改模块名")
    @RequestMapping(value = "/update", method = RequestMethod.POST)
   public BaseVo updateMenu(@RequestBody MenuEditParam  param) {
       BaseVo result = new BaseVo();
        if (StringUtils.isBlank(param.getMenuId()) || StringUtils.isNumeric(param.getMenuId())|| param.getModuleId() == 0 || StringUtils.isBlank(param.getMenuCode())||
 StringUtils.isBlank(param.getMenuName())||
 StringUtils.isBlank(param.getDescription())||
 StringUtils.isBlank(param.getWebUrl())||
 StringUtils.isBlank(param.getIconUrl())||
 StringUtils.isBlank(param.getCreateTime())||
 param.getUpdateTime() == 0    ){
            result.setCode(Constant.RESPONSE_PARAM_ERROR_CODE);
            result.setMsg(Constant.RESPONSE_PARAM_ERROR_MSG);
            return result;
        }
        //进行字符串的数字验证
        int success = menuService.updateMenu(param);
        if (success == 0) {
            result.setCode(Constant.RESPONSE_UPDATE_ERROR_CODE);
            result.setMsg(Constant.RESPONSE_UPDATE_ERROR_MSG);
        }
        return result;
    }
    @Transactional
    @ResponseBody
    @ApiOperation(value = "删除模块名", notes = "删除模块名")
    @RequestMapping(value = "/delete", method = RequestMethod.DELETE)
    public BaseVo deleteMenu(@RequestParam String menuIds) {
       BaseVo result = new BaseVo();
        if (StringUtils.isBlank(menuIds)) {
           result.setCode(Constant.RESPONSE_PARAM_ERROR_CODE);
           result.setMsg(Constant.RESPONSE_PARAM_ERROR_MSG);
           return result;
        }
        int success = menuService.deleteMenuList(menuIds);
       if (success == 0) {
           result.setCode(Constant.RESPONSE_DELETE_ERROR_CODE);
           result.setMsg(Constant.RESPONSE_DELETE_ERROR_MSG);
       }
        return result;
    }
    @ResponseBody
   @ApiOperation(value = "查询模块名", notes = "查询模块名")
    @RequestMapping(value = "/select", method = RequestMethod.GET)
   public BaseVo selectMenu(@RequestParam(required = false) String companyNumber,
                                @RequestParam(required = false) String appNumber,
                                @RequestParam String lang,
                               @RequestParam(required = false) String key,
                              @RequestParam(required = false, defaultValue = "0") long order,
                                @RequestParam int pageIndex,
                                @RequestParam int pageSize) {
        BaseVo result = new BaseVo();
        if (StringUtils.isBlank(lang) || pageIndex == 0 || pageSize == 0) {
           result.setCode(Constant.RESPONSE_PARAM_ERROR_CODE);
           result.setMsg(Constant.RESPONSE_PARAM_ERROR_MSG);
           return result;
        }
        if (appNumber != null && StringUtils.isBlank(appNumber)) {
            result.setCode(Constant.RESPONSE_PARAM_ERROR_CODE);
            result.setMsg(Constant.RESPONSE_PARAM_ERROR_MSG);
            return result;
        }
        if (companyNumber != null && StringUtils.isBlank(companyNumber)) {
            result.setCode(Constant.RESPONSE_PARAM_ERROR_CODE);
            result.setMsg(Constant.RESPONSE_PARAM_ERROR_MSG);
            return result;
        }
        MenuBackVo menuBackVo = new MenuBackVo();
        List<MenuSelectVo> menuSelectVoList = new ArrayList<>();
        MenuSelectParam menuSelectParam = new MenuSelectParam();
        List<Menu> menuList = menuService.selectMenu(menuSelectParam);
        menuList.forEach(menu->menuSelectVoList.add(new MenuSelectVo(menu)));
        menuBackVo.setMenuList(menuSelectVoList);
        menuBackVo.setCount(menuService.countMenu(menuSelectParam));
        result.setData(menuBackVo);
        return result;
    }
    @ResponseBody
    @ApiOperation(value = "查看模块名信息", notes = "查看模块名信息")
    @RequestMapping(value = "/info", method = RequestMethod.GET)
    public BaseVo selectMenu(@RequestParam String menuId) {
        BaseVo result = new BaseVo();
       if (StringUtils.isBlank(menuId) || !StringUtils.isNumeric(menuId)) {
            result.setCode(Constant.RESPONSE_PARAM_ERROR_CODE);
            result.setMsg(Constant.RESPONSE_PARAM_ERROR_MSG);
            return result;
        }
        Menu   menu = menuService.getMenu(Long.parseLong(menuId));
       //自定义不存在错误
        if (menu == null) {
           result.setCode(111);
            result.setMsg("自定义不存在错误");
            return result;
        }
        MenuInfoVo menuInfoVo = new MenuInfoVo(menu);
        result.setData(menuInfoVo);
        return result;
   }
}
